package com.it.collections;

import java.util.*;

/**
 * 目标：掌握Collections集合工具类的使用
 */
public class Test {
    public static void main(String[] args) {
        // 1、public static <T> boolean addAll(Collection<? super T>c,T...elements): 为集合批量添加数据 参数1：Collection集合 参数2：可变参数
        List<String> names = new ArrayList<>();
        Collections.addAll(names, "张三", "王五", "李四", "张麻子");
        System.out.println(names);
        System.out.println("----------------");

        // 2、public static void shuffle(List<?> list): 打乱List集合中的元素顺序
        Collections.shuffle(names);
        System.out.println(names);
        System.out.println("----------------");

        // 3、public static <T> void sort(List<T> list): 对List集合中的元素进行升序排序
        List<Integer> list = new ArrayList<>();
        list.add(3);
        list.add(5);
        list.add(2);
        Collections.sort(list);
        System.out.println(list);

        List<Student> students = new ArrayList<>();
        students.add(new Student("至尊宝", 28, 169.9));
        students.add(new Student("至尊宝", 28, 169.9));
        students.add(new Student("蜘蛛精", 23, 160.9));
        students.add(new Student("紫霞", 26, 150.9));
        students.add(new Student("牛魔二", 26, 180.9));
        Collections.sort(students);
//        System.out.println(students);

        // 4、public static <T> void sort(List<T> list, Comparator<? super T> c): 对List集合中的元素，按照比较器对象指定的规则进行排序

//        Collections.sort(students, new Comparator<Student>() {
//            @Override
//            public int compare(Student o1, Student o2) {
//                return Double.compare(o1.getHeight(), o2.getHeight()); // 升序
//            }
//        });

        Collections.sort(students, (o1, o2) -> Double.compare(o1.getHeight(), o2.getHeight()));

        System.out.println(students);
    }
}
